Atmospheric Temperature#
https://www.ncei.noaa.gov/data/global-historical-climatology-network-daily/doc/GHCND_documentation.pdf
import warnings
warnings.filterwarnings("ignore")
import os
import sys
import folium
import numpy as np
sys.path.append("../../../../indicators_setup")
from ind_setup.plotting_int import plot_timeseries_interactive
from ind_setup.colors import get_default_line_colors
sys.path.append("../../../functions")
from data_downloaders import GHCN
Define location and variables of interest#
country = 'Palau'
vars_interest = ['TMIN', 'TMAX']
Get Data#
df_country = GHCN.get_country_code(country)
print(f'The GHCN code for {country} is {df_country["Code"].values[0]}')
The GHCN code for Palau is PS
df_stations = GHCN.download_stations_info()
df_country_stations = df_stations[df_stations['ID'].str.startswith(df_country.Code.values[0])]
print(f'There are {df_country_stations.shape[0]} stations in {country}')
There are 13 stations in Palau
GHCND_dir = 'https://www.ncei.noaa.gov/data/global-historical-climatology-network-daily/access/'
for var in vars_interest:
globals()[f"dict_{var}"], IDS = GHCN.extract_dict_data_var(GHCND_dir, var, df_country_stations)
Plot Data#
map = folium.Map(location=[df_country_stations.iloc[0].Latitude-.25, df_country_stations.iloc[0].Longitude], zoom_start=10)
# Color list
colors = get_default_line_colors()
# Add markers
ids_with_data = df_country_stations[df_country_stations['ID'].isin(np.unique(IDS))]
for i in range(len(ids_with_data)):
folium.Marker(
location=[ids_with_data.iloc[i].Latitude, ids_with_data.iloc[i].Longitude],
popup=ids_with_data.iloc[i]['ID'] + ids_with_data.iloc[i]['Name'],
icon=folium.DivIcon(
html=f'<div style="font-size: 25px; color: white; background-color: {colors[i]}; line-height: 1; width: 24px; padding: 0px;">☉</div>'
)
).add_to(map)
map
Make this Notebook Trusted to load map: File -> Trust Notebook
for var in vars_interest:
dict_plot = globals()[f'dict_{var}']
fig = plot_timeseries_interactive(dict_plot, trendline=False, ylims = [5, 40])
Using Koror Station#
Analysis of how much the maximum and minimum temperatures over time are changing.
The analysis of the difference between these 2 variables will allow us to know how the daily variability is being modified
id = 'PSW00040309' # Koror Station
dict_min = GHCN.extract_dict_data_var(GHCND_dir, 'TMIN', df_country_stations.loc[df_country_stations['ID'] == id])
dict_max = GHCN.extract_dict_data_var(GHCND_dir, 'TMAX', df_country_stations.loc[df_country_stations['ID'] == id])
import pandas as pd
st_data = pd.concat([dict_min[0][0]['data'], (dict_max[0][0]['data'])], axis=1).dropna()
st_data['diff'] = st_data['TMAX'] - st_data['TMIN']
st_data = st_data.resample('Y').mean()
st_data.plot(y='diff', title='Annual difference between TMAX and TMIN', color='black', legend=False)
<Axes: title={'center': 'Annual difference between TMAX and TMIN'}, xlabel='DATE'>
dict_plot = [{'data' : st_data, 'var' : 'TMIN', 'ax' : 1, 'label' : 'TMIN'},
# {'data' : st_data, 'var' : 'TMAX', 'ax' : 1, 'label' : 'TMAX'},
# {'data' : st_data, 'var' : 'diff', 'ax' : 1, 'label' : 'Difference TMAX - TMIN'}
]
dict_plot[0].get('data')
| TMIN | TMAX | diff | |
|---|---|---|---|
| DATE | |||
| 1951-12-31 | 24.150543 | 30.924457 | 6.773913 |
| 1952-12-31 | 23.837978 | 30.904645 | 7.066667 |
| 1953-12-31 | 24.088767 | 31.039726 | 6.950959 |
| 1954-12-31 | 25.000548 | 31.084384 | 6.083836 |
| 1955-12-31 | 23.756986 | 30.741918 | 6.984932 |
| ... | ... | ... | ... |
| 2020-12-31 | 25.131752 | 29.885036 | 4.753285 |
| 2021-12-31 | 24.745042 | 28.618414 | 3.873371 |
| 2022-12-31 | 24.541781 | 29.917466 | 5.375685 |
| 2023-12-31 | 25.518440 | 30.079787 | 4.561348 |
| 2024-12-31 | 25.841463 | 30.137979 | 4.296516 |
74 rows × 3 columns
dict_plot = [{'data' : st_data, 'var' : 'TMIN', 'ax' : 1, 'label' : 'TMIN'}]
fig = plot_timeseries_interactive(dict_plot, trendline=True)
dict_plot = [{'data' : st_data, 'var' : 'TMAX', 'ax' : 1, 'label' : 'TMAX'}]
fig = plot_timeseries_interactive(dict_plot, trendline=True)
dict_plot = [{'data' : st_data, 'var' : 'diff', 'ax' : 1, 'label' : 'Difference TMAX - TMIN'}]
fig = plot_timeseries_interactive(dict_plot, trendline=True)